package com.bj58.migrate.helper.dao;

import com.bj58.sfft.utility.dao.basedao.DAOBase;
import com.bj58.sfft.utility.dao.basedao.DAOHelper;

/**
 * 数据库帮助类
 * 
 */
public class DatabaseHelper {

	private DAOHelper daoHelper = null; // 数据库连接帮助类
	private volatile static DatabaseHelper dbInstance = null;

	private DatabaseHelper() {
	}

	public DAOHelper getDaoHelper() {
		return daoHelper;
	}

	public void setDaoHelper(DAOHelper daoHelper) {
		this.daoHelper = daoHelper;
	}

	/**
	 * 获取数据库连接实例
	 * @return
	 */
	public static DatabaseHelper getInstance() {

		if (dbInstance == null) {
			synchronized (DatabaseHelper.class) {
				if (dbInstance != null) {
					return dbInstance;
				}
				dbInstance = new DatabaseHelper();
				try {
					// String dbpath = File.separator + "opt" + File.separator + "wf" + File.separator + "dia_wormhole"
					// + File.separator +
					// "db.properties";
					String dbpath = "/opt/apps/app/avgsalary/conf/dbvote.properties";
					System.out.println(dbpath);
					dbInstance.setDaoHelper(DAOBase.createIntrance(dbpath));
				} catch (Exception ex) {
					dbInstance = null;
					ex.printStackTrace();
				}
			}
		}
		return dbInstance;
	}
	
}
